/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   26.04.2010
 * @version SVN: $Id: ProductListEntry.java 115 2010-05-09 12:30:12Z christian-kerl@web.de $
 */
package org.cakis.server.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.cakis.server.service.util.BaseProductToProductAdapter;
import org.hibernate.validator.Min;

/**
 * ProductListEntry
 *
 * @author Christian Kerl
 */
@Entity
public class ProductListEntry implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Integer version;

    private ProductList productList;

    private Integer count;
    private BaseProduct product;

    public ProductListEntry() {
        this(null, 1);
    }

    public ProductListEntry(BaseProduct product, Integer count) {
        setProduct(product);
        setCount(count);
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Version
    public Integer getVersion() {
        return version;
    }

    @SuppressWarnings("unused")
    private void setVersion(Integer version) {
        this.version = version;
    }

    @ManyToOne
    @XmlTransient
    public ProductList getProductList() {
        return productList;
    }

    public void setProductList(ProductList productList) {
        this.productList = productList;
    }

    @Column(name="_count")
    @Min(0)
    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    @XmlJavaTypeAdapter(BaseProductToProductAdapter.class)
    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    public BaseProduct getProduct() {
        return product;
    }

    public void setProduct(BaseProduct product) {
        this.product = product;
    }
}
